package main.resources.controller;

import java.util.List;

import main.resources.controller.command.category.CategoryEditCommand;
import main.resources.controller.command.category.CategoryIncludeCommand;
import main.resources.controller.command.category.CategoryRemoveCommand;
import main.resources.controller.command.chat.ChatEditCommand;
import main.resources.controller.command.chat.ChatIncludeCommand;
import main.resources.controller.command.chat.ChatRemoveCommand;
import main.resources.controller.command.choice.ChoiceEditCommand;
import main.resources.controller.command.choice.ChoiceIncludeCommand;
import main.resources.controller.command.choice.ChoiceRemoveCommand;
import main.resources.controller.command.course.CourseEditCommand;
import main.resources.controller.command.course.CourseIncludeCommand;
import main.resources.controller.command.course.CourseRemoveCommand;
import main.resources.controller.command.forum.ForumEditCommand;
import main.resources.controller.command.forum.ForumIncludeCommand;
import main.resources.controller.command.forum.ForumRemoveCommand;
import main.resources.controller.command.lesson.LessonEditCommand;
import main.resources.controller.command.lesson.LessonIncludeCommand;
import main.resources.controller.command.lesson.LessonRemoveCommand;
import main.resources.controller.command.option.ChoiceOptionEditCommand;
import main.resources.controller.command.option.ChoiceOptionIncludeCommand;
import main.resources.controller.command.option.ChoiceOptionRemoveCommand;
import main.resources.controller.dao.moodle.MdlChatDao;
import main.resources.controller.dao.moodle.MdlChoiceDao;
import main.resources.controller.dao.moodle.MdlChoiceOptionDao;
import main.resources.controller.dao.moodle.MdlCourseCategoryDao;
import main.resources.controller.dao.moodle.MdlCourseDao;
import main.resources.controller.dao.moodle.MdlForumDao;
import main.resources.controller.dao.moodle.MdlLessonDao;
import main.resources.exceptions.DaoException;
import main.resources.exceptions.InvalidDateException;
import main.resources.model.Fabrica;
import main.resources.model.entity.moodle.MdlChat;
import main.resources.model.entity.moodle.MdlChoice;
import main.resources.model.entity.moodle.MdlChoiceOption;
import main.resources.model.entity.moodle.MdlCourse;
import main.resources.model.entity.moodle.MdlCourseCategory;
import main.resources.model.entity.moodle.MdlForum;
import main.resources.model.entity.moodle.MdlLesson;
import main.resources.view.Fachada;

public class AtidFacade implements Fachada {

	private AtidControlAgent agente;
	
	public AtidFacade() {
		agente = new AtidControlAgent();
	}
	
	public MdlCourseCategory cadastrarCategoria(String nome, String descricao) {
		return Fabrica.criarCategoria(nome, descricao);
	}
	
	public void incluirCategoria(MdlCourseCategory categoria) throws DaoException {
		this.agente.setCommand(new CategoryIncludeCommand(categoria));
		this.agente.wasCalled();
	}
		
	public void alterarCategoria(MdlCourseCategory categoria) throws DaoException {
		this.agente.setCommand(new CategoryEditCommand(categoria));
		this.agente.wasCalled();
	}
	
	public void removerCategoria(MdlCourseCategory categoria) throws DaoException {
		this.agente.setCommand(new CategoryRemoveCommand(categoria.getId()));
		this.agente.wasCalled();
	}
	
	public MdlCourseCategory buscarCategoria(String idCategoria) throws DaoException {
		return MdlCourseCategoryDao.getInstance().find(idCategoria);
	}
	
	public List<MdlCourseCategory> listarCategoria() throws DaoException {
		return MdlCourseCategoryDao.getInstance().listAll();
	}

	@Override
	public MdlCourse cadastrarCurso(MdlCourseCategory categoria, String nomeCompleto,
			String nomeCurto, String data, String numSecoes)
			throws InvalidDateException {
		return Fabrica.criarCurso(categoria, nomeCompleto, nomeCurto, data, numSecoes);
	}

	@Override
	public void incluirCurso(MdlCourse curso) throws DaoException {
		this.agente.setCommand(new CourseIncludeCommand(curso));
		this.agente.wasCalled();
	}

	@Override
	public void alterarCurso(MdlCourse curso) throws DaoException {
		this.agente.setCommand(new CourseEditCommand(curso));
		this.agente.wasCalled();
	}

	@Override
	public void removerCurso(MdlCourse curso) throws DaoException {
		this.agente.setCommand(new CourseRemoveCommand(curso.getId()));
		this.agente.wasCalled();
	}

	@Override
	public MdlCourse buscarCurso(String idCurso) throws DaoException {
		return MdlCourseDao.getInstance().find(idCurso);
	}

	@Override
	public List<MdlCourse> listarCurso() throws DaoException {
		return MdlCourseDao.getInstance().listAll();
	}	
	
	public MdlChat cadastrarChat(MdlCourse curso, String nome, String introducao, String data) throws InvalidDateException {
		return Fabrica.criarChat(curso, nome, introducao, data);
	}
	
	public void incluirChat(MdlChat chat) throws DaoException {
		this.agente.setCommand(new ChatIncludeCommand(chat));
		this.agente.wasCalled();
	}
		
	public void alterarChat(MdlChat chat) throws DaoException {
		this.agente.setCommand(new ChatEditCommand(chat));
		this.agente.wasCalled();
	}
	
	public void removerChat(MdlChat chat) throws DaoException {
		this.agente.setCommand(new ChatRemoveCommand(chat.getId()));
		this.agente.wasCalled();
	}
	
	public MdlChat buscarChat(String idChat) throws DaoException {
		return MdlChatDao.getInstance().find(idChat);
	}
	
	public List<MdlChat> listarChat() throws DaoException {
		return MdlChatDao.getInstance().listAll();
	}
	
	public MdlChoice cadastrarEscolha(MdlCourse curso, String nome, String introducao, String data) throws InvalidDateException {
		return Fabrica.criarEscolha(curso, nome, introducao, data);
	}
	
	public void incluirEscolha(MdlChoice escolha) throws DaoException {
		this.agente.setCommand(new ChoiceIncludeCommand(escolha));
		this.agente.wasCalled();
	}
	
	public void editEscolha(MdlChoice escolha) throws DaoException {
		this.agente.setCommand(new ChoiceEditCommand(escolha));
		this.agente.wasCalled();
	}
	
	public void removerEscolha(MdlChoice escolha) throws DaoException {
		this.agente.setCommand(new ChoiceRemoveCommand(escolha.getId()));
		this.agente.wasCalled();
	}
	
	public MdlChoice buscarEscolha(String idEscolha) throws DaoException {
		return MdlChoiceDao.getInstance().find(idEscolha);
	}
	
	public List<MdlChoice> listarEscolha() throws DaoException {
		return MdlChoiceDao.getInstance().listAll();
	}
	
	public MdlChoiceOption cadastrarOpcaoDeEscolha(MdlChoice escolha, String texto, String data) throws InvalidDateException {
		return Fabrica.criarOpcaoDeEscolha(escolha, texto, data);
	}
	
	public void incluirOpcaoDeEscolha(MdlChoiceOption opcao) throws DaoException {
		this.agente.setCommand(new ChoiceOptionIncludeCommand(opcao));
		this.agente.wasCalled();
	}
	
	public void editOpcaoDeEscolha(MdlChoiceOption opcao) throws DaoException {
		this.agente.setCommand(new ChoiceOptionEditCommand(opcao));
		this.agente.wasCalled();
	}
	
	public void removerOpcaoDeEscolha(MdlChoiceOption opcao) throws DaoException {
		this.agente.setCommand(new ChoiceOptionRemoveCommand(opcao.getId()));
		this.agente.wasCalled();
	}
	
	public MdlChoiceOption buscarOpcaoDeEscolha(String idOpcao) throws DaoException {
		return MdlChoiceOptionDao.getInstance().find(idOpcao);
	}
	
	public List<MdlChoiceOption> listarOpcaoDeEscolha() throws DaoException {
		return MdlChoiceOptionDao.getInstance().listAll();
	}
	
	public MdlForum cadastrarForum(MdlCourse curso, String nome, String introducao, String data) throws InvalidDateException {
		return Fabrica.criarForum(curso, nome, introducao, data);
	}
	
	public void incluirForum(MdlForum forum) throws DaoException {
		this.agente.setCommand(new ForumIncludeCommand(forum));
		this.agente.wasCalled();
	}
	
	public void editForum(MdlForum forum) throws DaoException {
		this.agente.setCommand(new ForumEditCommand(forum));
		this.agente.wasCalled();
	}
	
	public void removerForum(MdlForum forum) throws DaoException {
		this.agente.setCommand(new ForumRemoveCommand(forum.getId()));
		this.agente.wasCalled();
	}
	
	public MdlForum buscarForum(String idForum) throws DaoException {
		return MdlForumDao.getInstance().find(idForum);
	}
	
	public List<MdlForum> listarForum() throws DaoException {
		return MdlForumDao.getInstance().listAll();
	}
	
	public MdlLesson cadastrarLicao(MdlCourse curso, String nome, String senha, String data) throws InvalidDateException {
		return Fabrica.criarLicao(curso, nome, senha, data);
	}
	
	public void incluirLicao(MdlLesson licao) throws DaoException {
		this.agente.setCommand(new LessonIncludeCommand(licao));
		this.agente.wasCalled();
	}
	
	public void editLicao(MdlLesson licao) throws DaoException {
		this.agente.setCommand(new LessonEditCommand(licao));
		this.agente.wasCalled();
	}
	
	public void removerLicao(MdlLesson licao) throws DaoException {
		this.agente.setCommand(new LessonRemoveCommand(licao.getId()));
		this.agente.wasCalled();
	}
	
	public MdlLesson buscarLicao(String idLicao) throws DaoException {
		return MdlLessonDao.getInstance().find(idLicao);
	}
	
	public List<MdlLesson> listarLicao() throws DaoException {
		return MdlLessonDao.getInstance().listAll();
	}
}
